package com.onesports.intelligent.k12.polarlight.service.course.manage;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.onesports.framework.kit.common.util.ParamUtils;
import com.onesports.intelligent.k12.polarlight.common.domain.entity.BaseEntity;
import com.onesports.intelligent.k12.polarlight.domain.entity.course.CourseOpen;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseOpenVO;
import com.onesports.intelligent.k12.polarlight.mapper.course.CourseOpenMapper;
import com.onesports.intelligent.k12.polarlight.util.BeanCopyUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author FPH
 * @since 2022年7月11日10:18:18
 */
@Service
public class CourseOpenService extends ServiceImpl<CourseOpenMapper, CourseOpen> {

    /**
     * 根据机构课程id获取课程开设时间
     *
     * @param courseId       课程id
     * @param organizationId 机构id
     */
    public List<CourseOpenVO> listByCourseIdAndOrganizationId(String courseId, String organizationId) {
        List<CourseOpen> list = this.list(new LambdaQueryWrapper<CourseOpen>()
                .eq(CourseOpen::getCourseId, courseId)
                .eq(CourseOpen::getOrganizationId, organizationId)
                .eq(BaseEntity::getDeleted, false)
                .orderByAsc(CourseOpen::getStartTime)
                .orderByAsc(CourseOpen::getEndTime));
        if (ParamUtils.isEmpty(list)) {
            return new ArrayList<>();
        }
        return BeanCopyUtil.copyListProperties(list, CourseOpenVO::new);
    }


    public List<CourseOpen> listByCourseIdsAndOrganizationId(List<String> courseIds, String organizationId) {
        return this.list(new LambdaQueryWrapper<CourseOpen>()
                .in(CourseOpen::getCourseId, courseIds)
                .eq(CourseOpen::getOrganizationId, organizationId)
                .eq(BaseEntity::getDeleted, false)
                .orderByAsc(CourseOpen::getStartTime)
                .orderByAsc(CourseOpen::getEndTime));
    }

}
